package com.itheima.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.MenuDao;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 检查服务
 *
 * @create 2020/11/16 0016 11:32
 */
@Service
@Transactional
public class MenuServiceImpl implements MenuService {
    
    //注入MenuDao对象
    @Autowired
    private MenuDao menuDao;
    
    /**
     * 增加菜单
     *
     * @param menu
     */
    @Override
    public void add(Menu menu) {
        menuDao.add(menu);
    }
    
    /**
     * 删除菜单
     *
     * @param id
     */
    @Override
    public void delete(Integer id) {
        menuDao.deleteById(id);
    }
    
    /**
     * 修改菜单
     *
     * @param menu
     */
    @Override
    public void edit(Menu menu) {
        menuDao.edit(menu);
    }
    
    /**
     * 分页-条件查询菜单
     *
     * @param queryPageBean
     * @return
     */
    @Override
    public PageInfo<Menu> selectByCondition(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        List<Menu> all = menuDao.selectByCondition(queryPageBean.getQueryString());
        return new PageInfo(all);
        
    }
    
    /**
     * 根据id查询菜单
     *
     * @param id
     * @return
     */
    @Override
    public Menu findById(Integer id) {
        return menuDao.findById(id);
    }
    
    @Override
    public List<Menu> findAll() {
        return menuDao.findAll();
    }
}
